package qeb.handheldmedical.adapter;

import org.json.JSONArray;
import org.json.JSONObject;

import qeb.handheldmedical.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ConsultationDetailAdapter extends BaseAdapter{

	private static final String TAG = "ConsultationDetailJsonArray";
	
	//private ImageSwitcher mImageLoader;
	private int mCount;
	private Context mContext;
	private JSONArray consultationDetailJsonArray =null;
	
	public ConsultationDetailAdapter(int count, Context context, JSONArray cltJsonArray) {
		this.mCount = count;
		this.mContext = context;
		this.consultationDetailJsonArray = cltJsonArray;
		//mImageLoader = new ImageSwitcher(context);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mCount;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewholder = null;
		convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_consultationinfo, null);
			viewholder = new ViewHolder();
			viewholder.tv_bqnm = (TextView)convertView.findViewById(R.id.tv_bqnm);
			viewholder.tv_ysxm = (TextView)convertView.findViewById(R.id.tv_ysxm);
			viewholder.tv_ksmc = (TextView)convertView.findViewById(R.id.tv_ksmc);
			viewholder.tv_qqrq = (TextView)convertView.findViewById(R.id.tv_qqrq);
			viewholder.tv_ksnm2 = (TextView)convertView.findViewById(R.id.tv_ksnm2);
			viewholder.tv_zlqk = (TextView)convertView.findViewById(R.id.tv_zlqk);
			viewholder.tv_zlqk1 = (TextView)convertView.findViewById(R.id.tv_zlqk1);
			viewholder.tv_hzly = (TextView)convertView.findViewById(R.id.tv_hzly);
			viewholder.tv_hzly1 = (TextView)convertView.findViewById(R.id.tv_hzly1);			
			viewholder.tv_df = (TextView)convertView.findViewById(R.id.tv_df);
			viewholder.tv_jcfx = (TextView)convertView.findViewById(R.id.tv_jcfx);
			viewholder.tv_jcfx1 = (TextView)convertView.findViewById(R.id.tv_jcfx1);
			viewholder.tv_dfjy = (TextView)convertView.findViewById(R.id.tv_dfjy);
			viewholder.tv_dfjy1 = (TextView)convertView.findViewById(R.id.tv_dfjy1);
			convertView.setTag(viewholder);
			
			try {
				JSONObject clt = consultationDetailJsonArray.getJSONObject(position);
				if(clt!=null)
				{
					/*viewholder.tv_bqnm.setText(xt.getString("CLSJ"));
					viewholder.tv_ysxm.setText(xt.getString("CLJG"));
					viewholder.tv_ksmc.setText(xt.getString("JLHSN"));
					viewholder.tv_qqrq.setText(xt.getString("CLSJ"));
					viewholder.tv_ksnm2.setText(xt.getString("CLJG"));
					viewholder.tv_zlqk.setText(xt.getString("JLHSN"));
					viewholder.tv_zlqk1.setText(xt.getString("CLSJ"));
					viewholder.tv_hzly.setText(xt.getString("CLJG"));
					viewholder.tv_hzly1.setText(xt.getString("JLHSN"));
					viewholder.tv_df.setText(xt.getString("CLSJ"));
					viewholder.tv_jcfx.setText(xt.getString("CLJG"));
					viewholder.tv_jcfx1.setText(xt.getString("JLHSN"));
					viewholder.tv_dfjy.setText(xt.getString("CLJG"));
					viewholder.tv_dfjy1.setText(xt.getString("JLHSN"));*/
					viewholder.tv_bqnm.setText("请求: "+"二十二病区");
					if(clt.getString("DFDNAME")!=null&&clt.getString("DFDNAME")!="")
						viewholder.tv_ysxm.setText(clt.getString("DFDNAME")+" 医师");
					if(clt.getString("DFKNAME")!=null&&clt.getString("DFKNAME")!="")
						viewholder.tv_ksmc.setText(clt.getString("DFKNAME")+"科会诊");
					viewholder.tv_qqrq.setText("日期 "+clt.getString("QQTIME"));
					viewholder.tv_ksnm2.setText("兹有"+clt.getString("QQKNAME")+clt.getString("BQNAME")+clt.getString("PCH")+"病人"+clt.getString("PNAME")+"希于会诊");	
					viewholder.tv_zlqk.setText("病历摘要及诊疗情况：");
					viewholder.tv_zlqk1.setText(clt.getString("BQZY"));		
					viewholder.tv_hzly.setText("会诊理由与目的：");		
					viewholder.tv_hzly1.setText(clt.getString("HZMD"));
					viewholder.tv_df.setText("答复: ");
					viewholder.tv_jcfx.setText("检查与分析：");
					viewholder.tv_jcfx1.setText(clt.getString("DFCONTENT"));		
					viewholder.tv_dfjy.setText("会诊结论与建议：");				
					viewholder.tv_dfjy1.setText(clt.getString("JLJY"));
					
				}
			} catch (Exception e) {
				// TODO: handle exception
				Log.e(TAG, e.toString());
			}
		
		return convertView;
	}
	
	static class ViewHolder {
		//ImageView imgPatient;
		TextView tv_bqnm;
		TextView tv_ysxm;
		TextView tv_ksmc;
		TextView tv_qqrq;
		TextView tv_ksnm2;
		TextView tv_zlqk;
		TextView tv_zlqk1;
		TextView tv_hzly;
		TextView tv_hzly1;
		TextView tv_df;
		TextView tv_jcfx;
		TextView tv_jcfx1;
		TextView tv_dfjy;
		TextView tv_dfjy1;
	}
}